<?php
include("include/config.inc.php");
if(!isset($_SESSION['s_activId']))
{
  header("location:checklogin.php");
  exit();
}
$k=0;
$unloadArray   = array();
$selectedTruck = isset($_REQUEST['truckMasterId']) ? $_REQUEST['truckMasterId'] : 0;
if(isset($_REQUEST['truckMasterId']) && $_REQUEST['truckMasterId'] > 0)
{
 $selectUnloadTruck = "SELECT fromId,toId,invoiceNo,DATE_FORMAT(invoiceDate,'%d-%m-%Y')AS invoiceDate,truckNo,
                               fromTable.branchName AS fromName,truckNo,toTable.branchName AS toName
	                         FROM loadinginvoice
	                         JOIN truckmaster ON truckmaster.truckId = loadinginvoice.truckId
	                         JOIN branch AS fromTable ON fromTable.branchId = loadinginvoice.fromId
                           JOIN branch AS toTable ON toTable.branchId = loadinginvoice.toId
	                         WHERE loadinginvoice.truckId = ".$selectedTruck."
	                         AND unloadStatus = 'Y'
	                        GROUP BY invoiceNo";
  $selectUnloadTruckRes = mysql_query($selectUnloadTruck);
  while($unloadRow = mysql_fetch_array($selectUnloadTruckRes))
  {
  	$unloadArray[$k]['fromName']        = $unloadRow['fromName'];
  	$unloadArray[$k]['toName']          = $unloadRow['toName'];
  	$unloadArray[$k]['truckNo']         = $unloadRow['truckNo'];
  	$unloadArray[$k]['invoiceNo']       = $unloadRow['invoiceNo'];
  	$unloadArray[$k]['invoiceDate']     = $unloadRow['invoiceDate'];
  	$k++;
  }
}

$i=0;
$truckArray = array();
$selectTrck = "SELECT truckId,truckNo
                  FROM truckMaster";  
$selectTrckRes = mysql_query($selectTrck);
while($truckRow = mysql_fetch_array($selectTrckRes))
{
	$truckArray['truckId'][$i]  = $truckRow['truckId'];
	$truckArray['truckNo'][$i]  = $truckRow['truckNo'];
	$i++;
}
include("./bottom.php");
$smarty->assign('truckArray',$truckArray);
$smarty->assign('selectedTruck',$selectedTruck);
$smarty->assign('unloadArray',$unloadArray);
$smarty->display('truckUnload.tpl');
?>